package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.BlogDAO;
import com.ssm.blog.pojo.Blog;
import com.ssm.blog.pojo.criteria.BlogCriteria;
import com.ssm.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogDAO blogDAO;

    @Override
    public void addBlog(Blog blog) {
        blogDAO.addBlog(blog);
        blogDAO.addBlogCount(blog.getId());
    }

    @Override
    public PageInfo<Blog> getBlogList(BlogCriteria criteria, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize,"id desc");
        List<Blog> blogList = blogDAO.getBlogList(criteria);
        PageInfo<Blog> pageInfo = new PageInfo<>(blogList);
        return pageInfo;
    }

    @Override
    public Blog getBlogById(Integer id) {
        return blogDAO.getBlogById(id);
    }
}
